package com.jbm.enterapplication.service

import android.app.Service
import android.content.Intent
import android.os.IBinder
import com.jbm.core.client.MainCallback
import com.jbm.core.common.ConnectAgent
import com.jbm.core.iface.IFileObject
import com.jbm.enterapplication.mode.MyServiceModel
import com.jbm.enterapplication.sharedprefer.SharedPreActivity
import com.jbm.onehome.iface.*
import java.math.BigDecimal
import java.util.*

/**
 * Created by 家帮忙 on 2017/9/4.
 */
class ServiceConn :Service{
    private var  callback: MainCallback

    constructor() {
         callback = object : MainCallback{
            override fun NewAccount(ca: ConnectAgent?) {
            }
            override fun RemoveAccount(account_id: Int?) {
            }

            override fun UpdateAccount(pullall: Boolean, ca: ConnectAgent?) {
            }

            override fun OfflineAccount(status: Int, ca: ConnectAgent?) {
            }

            override fun NewDevice(ca: ConnectAgent?) {
            }

            override fun RemoveDevice(account_id: Int?) {
            }

            override fun UpdateDevice(pullall: Boolean, ca: ConnectAgent?) {
            }

            override fun OfflineDevice(ca: ConnectAgent?) {
            }

            override fun NewText(account_id: Int?, text: String?, timestamp: Long) {
            }

            override fun NewFile(account_id: Int?, fo: IFileObject?, timestamp: Long) {
            }

            override fun NewPay(account_id: Int?, msg: String?, fee: BigDecimal?, paytype: String?, timestamp: Long) {
            }

            override fun CGNewText(cg_id: Int, account_id: Int?, text: String?, timestamp: Long) {
            }

            override fun CGNewFile(cg_id: Int, account_id: Int?, fo: IFileObject?, timestamp: Long) {
            }

            override fun AddContact(ce: ContactEntity?) {
            }

            override fun DropContact(ce: ContactEntity?) {
            }

            override fun Belogout() {
            }

            override fun getAllIFace(): MutableList<String> {
                return Arrays.asList(*("com.jbm.core.iface.IAcross|" +
                        "com.jbm.core.iface.ICallGroup|" +
                        "com.jbm.core.iface.IConnectAgent|" +
                        "com.jbm.core.iface.IFileObject|" +
                        "com.jbm.core.iface.IP2P|" +
                        "com.jbm.core.iface.IRegister|" +
                        "com.jbm.onehome.iface.AccSecretEntity|" +
                        "com.jbm.onehome.iface.AlipaylogEntity|" +
                        "com.jbm.onehome.iface.AppJudgeEntity|" +
                        "com.jbm.onehome.iface.BalanceEntity|" +
                        "com.jbm.onehome.iface.BusAuditLogEntity|" +
                        "com.jbm.onehome.iface.BusinessEntity|" +
                        "com.jbm.onehome.iface.CapitalAccEntity|" +
                        "com.jbm.onehome.iface.CertAddressEntity|" +
                        "com.jbm.onehome.iface.ClickTimesEntity|" +
                        "com.jbm.onehome.iface.ContactEntity|" +
                        "com.jbm.onehome.iface.EguardBtEntity|" +
                        "com.jbm.onehome.iface.EguardKeyEntity|" +
                        "com.jbm.onehome.iface.EguardLogEntity|" +
                        "com.jbm.onehome.iface.EnchashmentEntity|" +
                        "com.jbm.onehome.iface.EntranceGuardEntity|" +
                        "com.jbm.onehome.iface.ExchangeEntity|" +
                        "com.jbm.onehome.iface.ExProductEntity|" +
                        "com.jbm.onehome.iface.FocusEntity|" +
                        "com.jbm.onehome.iface.GeoInfoEntity|" +
                        "com.jbm.onehome.iface.GiGiHstyEntity|" +
                        "com.jbm.onehome.iface.GoodsEntity|" +
                        "com.jbm.onehome.iface.IAccCtrl|" +
                        "com.jbm.onehome.iface.IAcc|" +
                        "com.jbm.onehome.iface.IAplipay|" +
                        "com.jbm.onehome.iface.IAPPJudge|" +
                        "com.jbm.onehome.iface.IAppVersion|" +
                        "com.jbm.onehome.iface.IAttachment|" +
                        "com.jbm.onehome.iface.IBreakJob|" +
                        "com.jbm.onehome.iface.IBusinessCtrl|" +
                        "com.jbm.onehome.iface.ICertAddressCtrl|" +
                        "com.jbm.onehome.iface.ICertAddress|" +
                        "com.jbm.onehome.iface.IConfirmJob|" +
                        "com.jbm.onehome.iface.IDownloadMedia|" +
                        "com.jbm.onehome.iface.IEGLogCtrl|" +
                        "com.jbm.onehome.iface.IEGLog|" +
                        "com.jbm.onehome.iface.IEGuard|" +
                        "com.jbm.onehome.iface.IEGuardKeyCtrl|" +
                        "com.jbm.onehome.iface.IEGuardKey|" +
                        "com.jbm.onehome.iface.IExChangeCtrl|" +
                        "com.jbm.onehome.iface.IGeoEntityCtrl|" +
                        "com.jbm.onehome.iface.IGeoinfoCtrl|" +
                        "com.jbm.onehome.iface.IGeoinfo|" +
                        "com.jbm.onehome.iface.IGetJobList|" +
                        "com.jbm.onehome.iface.IInformationCtrl|" +
                        "com.jbm.onehome.iface.IJobTotal|" +
                        "com.jbm.onehome.iface.IJOrderCtrl|" +
                        "com.jbm.onehome.iface.IJOrder|" +
                        "com.jbm.onehome.iface.ILoadJob|" +
                        "com.jbm.onehome.iface.ILoginCtrl|" +
                        "com.jbm.onehome.iface.ILogin|" +
                        "com.jbm.onehome.iface.InfoAttachmentEntity|" +
                        "com.jbm.onehome.iface.InfoAuditLogEntity|" +
                        "com.jbm.onehome.iface.InfoGeoPriceEntity|" +
                        "com.jbm.onehome.iface.InfomationEntity|" +
                        "com.jbm.onehome.iface.InfoScopeEntity|" +
                        "com.jbm.onehome.iface.IOrderCtrl|" +
                        "com.jbm.onehome.iface.IorderEntity|" +
                        "com.jbm.onehome.iface.IOrder|" +
                        "com.jbm.onehome.iface.IOtherConfigCtrl|" +
                        "com.jbm.onehome.iface.IPayCtrl|" +
                        "com.jbm.onehome.iface.IPay|" +
                        "com.jbm.onehome.iface.IpointsCtrl|" +
                        "com.jbm.onehome.iface.IRegistCustomer|" +
                        "com.jbm.onehome.iface.ISaleActivity|" +
                        "com.jbm.onehome.iface.ISecretCtrl|" +
                        "com.jbm.onehome.iface.ISecret|" +
                        "com.jbm.onehome.iface.ISellerCtrl|" +
                        "com.jbm.onehome.iface.ISeller|" +
                        "com.jbm.onehome.iface.IStatBrokenEGuard|" +
                        "com.jbm.onehome.iface.IStatCtrl|" +
                        "com.jbm.onehome.iface.IStatDayEGuard|" +
                        "com.jbm.onehome.iface.IStatEGuardLog|" +
                        "com.jbm.onehome.iface.IStatVillage|" +
                        "com.jbm.onehome.iface.ISubmitJob|" +
                        "com.jbm.onehome.iface.ITotal|" +
                        "com.jbm.onehome.iface.ITrafficRstr|" +
                        "com.jbm.onehome.iface.IUploadMedia|" +
                        "com.jbm.onehome.iface.IVerifyCode|" +
                        "com.jbm.onehome.iface.IVersion|" +
                        "com.jbm.onehome.iface.IWeatherCtrl|" +
                        "com.jbm.onehome.iface.IWeather|" +
                        "com.jbm.onehome.iface.JobOrderEntity|" +
                        "com.jbm.onehome.iface.JordAttachmentEntity|" +
                        "com.jbm.onehome.iface.LoginEntity|" +
                        "com.jbm.onehome.iface.Login|" +
                        "com.jbm.onehome.iface.LoginLogEntity|" +
                        "com.jbm.onehome.iface.LoginRoleEntity|" +
                        "com.jbm.onehome.iface.Media|" +
                        "com.jbm.onehome.iface.MemberEntity|" +
                        "com.jbm.onehome.iface.MemLoginHstyEntity|" +
                        "com.jbm.onehome.iface.MGiEntity|" +
                        "com.jbm.onehome.iface.OrdAttachmentEntity|" +
                        "com.jbm.onehome.iface.OrderItemsEntity|" +
                        "com.jbm.onehome.iface.OtherconfigEntity|" +
                        "com.jbm.onehome.iface.PaybackEntity|" +
                        "com.jbm.onehome.iface.PicInputStream|" +
                        "com.jbm.onehome.iface.PicOutputStream|" +
                        "com.jbm.onehome.iface.PointsEntity|" +
                        "com.jbm.onehome.iface.PointsRuleEntity|" +
                        "com.jbm.onehome.iface.PraiseEntity|" +
                        "com.jbm.onehome.iface.RoleEntity|" +
                        "com.jbm.onehome.iface.SellerEntity|" +
                        "com.jbm.onehome.iface.SellerLoginHstyEntity|" +
                        "com.jbm.onehome.iface.StatisticalReportEntity|" +
                        "com.jbm.onehome.iface.TrafficrstrEntity|" +
                        "com.jbm.onehome.iface.VEguardLogEntity|" +
                        "com.jbm.onehome.iface.VerifyCodeEntity|" +
                        "com.jbm.onehome.iface.VoucherEntity|" +
                        "com.jbm.onehome.iface.WeatherEntity|" +
                        "com.jbm.onehome.iface.WxpaylogEntity|" +
                        "com.jbm.onehome.iface.CallGroupEntity").split("\\|".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray())
            }

            override fun ReConnect() {
            }

            override fun GPConfirmStart(cg_id: Int) {
            }

            override fun GPSelectCertAddress(cg_id: Int, ca: Array<out ICertAddress>?) {
            }

            override fun GPSelectCatalog(cg_id: Int, glist: MutableList<GoodsEntity>?) {
            }

            override fun GPSelectTeam(cg_id: Int, team: Array<out String>?) {
            }

            override fun DeliverCode(code: String?, memo: String?, from_id: Int?, to_id: Int?, timestamp: Long) {
            }

            override fun orderStatus(iorderEntity: IorderEntity?) {
            }

            override fun jobOrderStatus(jobOrderEntity: JobOrderEntity?) {
            }

            override fun addToUnit(cg: CallGroupEntity?) {
            }

        }

    }

    override fun onBind(intent: Intent?): IBinder? {
        return null
    }
var Isboocomm:Boolean?=false
    var myservicemode:MyServiceModel?=null
    var sharedprefer:SharedPreActivity?=null
    override fun onCreate() {
        sharedprefer= SharedPreActivity(baseContext)
        if (sharedprefer?.getIsConn()==true) {
            myservicemode = MyServiceModel(baseContext, callback, "关机")
            Isboocomm=true
        }

        super.onCreate()
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        if (Isboocomm==false){
            myservicemode = MyServiceModel(baseContext, callback, "开机")
        }
        Isboocomm=false




        return super.onStartCommand(intent, flags, startId)
    }


}